package com.lqk.principle.ocp.improve;

/**
 * @author lqk
 * @date 2021/11/25 21:13
 */
public class OcpImp {
    public static void main(String[] args) {
        // 使用看看存在的问题
        GraphicEditor graphicEditor = new GraphicEditor();
        graphicEditor.drawShape(new Rectangle());
        graphicEditor.drawShape(new Circle());
        graphicEditor.drawShape(new Triangle());
        graphicEditor.drawShape(new Other());
    }
}

// 这是一个用于绘图的工具[使用方]
class GraphicEditor {
    // 接收Shape对象，调用draw方法
    public void drawShape(Shape s) {
        s.draw();
    }
}

// Shape类，基类
abstract class Shape {
    public abstract void draw();
}

class Rectangle extends Shape {
    @Override
    public void draw() {
        System.out.println("矩形");
    }
}

class Circle extends Shape {
    @Override
    public void draw() {
        System.out.println("圆形");
    }
}

class Triangle extends Shape {
    @Override
    public void draw() {
        System.out.println("三角形");
    }
}

class Other extends Shape{
    @Override
    public void draw() {
        System.out.println("其他图形");
    }
}